1. Field of the Invention
The present invention relates to compilers and garbage collection in computer systems. More specifically, the present invention relates to a method and apparatus for developing an application using a first compiler and then compiling the application with a second compiler that provides support for efficient garbage collection.
2. Related Art
Programming languages with automatic memory management, such as the JAVA.TM. programming language from Sun Microsystems, Inc. of Palo Alto, Calif., are widely recognized for making software development easier. Unlike conventional programming languages, such as C or C++, that require programmers to use pointers and explicit memory allocation operations to manage dynamic data structures, languages such as the Java programming language take care of memory management automatically.
Automatic memory management systems typically allocate data objects from memory as they are needed during execution of a program. When memory objects are no longer being used by the program, they are typically reclaimed through a process known as "garbage collection."
Programming languages with automatic memory management relieve the programmer of the responsibility of explicitly managing memory, and this generally leads to better programming style. However, programming languages with automatic memory management also provide less control over memory allocation and pointer manipulation during program execution. This makes the behavior of the program harder to understand and predict. Furthermore, while languages with automatic memory management often provide reasonable performance in typical application programming tasks, in certain "systems programming" tasks involving time-critical system functions, the reduced control over memory management can cause performance problems. Programmers typically do not use programming languages with automatic memory management for systems programming tasks, but instead write systems programs using other, less elegant programming languages such as C or C++, which require explicit commands to allocate and deallocate memory.
One of the main performance problems for programs written in programming languages with automatic memory management is the garbage collection process. Garbage collection typically involves chasing down pointers in active data structures to determine which data objects are presently being referenced, so that the other data objects, which are no longer being referenced, can be reclaimed.
One problem in performing garbage collection is to identify objects in memory that are referenced by pointers on the system stack. One solution to this problem is to use proxy objects. Proxy objects are special system objects that point to data objects in memory. In order to use proxy objects, pointers on the system stack are modified so that they point to the proxy objects, which contain pointers to corresponding data objects in memory. This allows the garbage collection process to simply reference the proxy objects to determine which objects in memory are referenced by pointers in the stack. However, using proxy objects can be time-consuming and inefficient because a program that uses proxy objects must explicitly allocate and deallocate proxy objects, and must manipulate the proxy objects during references from the system stack.
Another solution to the problem of identifying objects referenced by the system stack is to modify a compiler so that it produces a "stack map" for each stack frame. A stack map identifies which items within a given stack frame contain pointers to objects in memory. This allows a garbage collection process to follow down the identified pointers in the system stack.
Unfortunately, many applications that implement garbage collections (such as virtual machines) have been developed using proxy objects, and these applications must be rewritten to take advantage of the performance advantages of stack maps. What is needed is a method and an apparatus that allows applications developed using proxy objects and a standard compiler to take advantage of the performance benefits of using compiler support to identify pointers within a system stack.